package com.zxjia.ssmp.controller;

import com.zxjia.ssmp.dto.AppIndexRequest;
import com.zxjia.ssmp.dto.ProductRequest;
import com.zxjia.ssmp.service.ProductService;
import com.zxjia.ssmp.vo.Result;
import com.zxjia.ssmp.vo.IndexVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Api(tags = "首页管理")
@RestController
@RequestMapping(value = "/api")
public class IndexController {

    @Autowired
    private ProductService productService;

    @ApiOperation(value = "查询商品类别信息")
    @PostMapping(value = "/index/getProductByCateId")
    public Result<IndexVo> getProductByCateId(@RequestBody ProductRequest request ) {
        return Result.success(productService.getProductCateById(request));
    }

    @ApiOperation(value = "搜索")
    @PostMapping(value = "/index/search")
    public Result<IndexVo> search(@RequestBody AppIndexRequest request) {
       return Result.success(productService.search(request));
    }

    @GetMapping("/saveAll")
    public void saveAll(){
        productService.saveAll();
    }

}
